<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script type="text/javascript" src="../../jQuery-JS/jquery-3.6.0.js"></script>
    <script type="text/javascript">
        /*
        需求：
        1.得到div或页面滚动条的坐标
        2.让div或页面的滚动条滚动到指定位置
        */
        $(function(){
            //1.得到div或页面滚动条的坐标
            var $btn1=$("#btn1");
            $btn1.click(function(){
                var $div=$("div");
                var $html=$("html");
                console.log($div.scrollTop());
                //目前默认情况body是零值，所以加不加都一样
                console.log($("html").scrollTop()+$("body").scrollTop());
                console.log($(document.body).scrollTop()+$(document.documentElement).scrollTop());
            })
            //2.让div或页面的滚动条滚动到指定位置
            var $btn2=$("#btn2");
            $btn2.click(function(){
                var $div=$("div");
                $div.scrollTop(150);
                //body默认情况是零值，所以可以不加
                $("html").scrollTop(20);
            })
        })
    </script>
</head>
<body style="height: 2000px;">
    <div style="border:1px solid black;width:100px;height:150px;overflow:auto">
        This is some text. This is some text. This is some text. This is some text.
        This is some text. This is some text. This is some text. This is some text.
        This is some text. This is some text. This is some text. This is some text.
        This is some text. This is some text. This is some text. This is some text.
        This is some text.
    </div>
    <br>
    <br>
    <br>
    <button id="btn1">得到scrollTop</button>
    <button id="btn2">设置scrollTop</button>
    <!--
        1.scrollTop()
        读取/设置滚动条的Y坐标
        2.$(document.body).scrollTop()+$(document.documentElement).scrollTop()
        读取页面滚动条的Y坐标（兼容chrome和IE）
        3.$("body,html").scrollTop(60)
        滚动到指定位置（兼容chrome和IE）
    -->
</body>
</html>